<template>
  <view>
    <!--绑定推荐人地址  注册码 -->
    <modal
      @cancel="closeModel"
      :show="addressModel"
      custom
      @click="subAddress"
      :title="'填写注册码'"
      :padding="'80rpx  28rpx 56rpx'"
      width="654rpx"
    >
      <view class="login-model-mix">
        <view class="wallet-model">
          <view class="model-header"> </view>
          <view class="model-content">
            <view class="subTitle">邀请码填入</view>
            <view class="address-input">
              <u--input
                placeholder=""
                placeholderStyle="color:#5D5D5D"
                v-model="Recommenderaddres"
                border="none"
                clearable
              ></u--input>
            </view>
            <view class="logn-btn" @click="subAddress()">{{ i18n.h5 }}</view>
          </view>
        </view>
      </view>
    </modal>
    <!-- 客服链接  平台客服-->
    <modal
      @cancel="closeModel"
      :show="custmreModel"
      custom
      :padding="'60rpx  28rpx 80rpx'"
      width="666rpx"
    >
      <view class="login-model-mix">
        <view class="wallet-model">
          <view class="model-header"> </view>
          <view class="model-content">
            <view class="subTitle">{{ i18n.h106 }}</view>
            <view class="linkAddress">{{ links }}</view>
            <view
              class="logn-btn links"
              :data-clipboard-text="links"
              @click="subInvite(links)"
              >{{ i18n.h24 }}</view
            >
          </view>
        </view>
      </view>
    </modal>
    <!-- 邀请好友链接 -->
    <modal
      @cancel="closeModel"
      :show="inviteModel"
      custom
      :padding="'60rpx  28rpx 80rpx'"
      width="666rpx"
    >
      <view class="login-model-mix">
        <view class="wallet-model">
          <view class="model-header"> </view>
          <view class="model-content">
            <view class="subTitle">{{ i18n.h76 }}</view>
            <view class="linkAddress">{{ invitelinks }}</view>
            <view
              class="logn-btn links"
              :data-clipboard-text="invitelinks"
              @click="subInvite(invitelinks)"
              >{{ i18n.h24 }}</view
            >
          </view>
        </view>
      </view>
    </modal>
    <!-- 登录 -->
    <modal
      :show="loginModel"
      custom
      width="654rpx"
      height="306rpx"
      radius="40rpx"
      :padding="'36rpx  44rpx 60rpx'"
    >
      <view class="login-model-mix">
        <view class="wallet-model">
          <view class="model-header"> </view>
          <view class="model-content">
            <view class="title">{{ i18n.h011 }}</view>
            <view class="logn-btn-larg" @click="toSing()">
              {{ i18n.h012 }}</view
            >
          </view>
        </view>
      </view>
    </modal>

    <!-- 退出登录 -->
    <modal
      :show="singModel"
      custom
      width="654rpx"
      radius="40rpx"
      :padding="'70rpx 56rpx '"
    >
      <view class="login-model-mix">
        <view class="wallet-model">
          <view class="model-header">
            <view></view>
          </view>
          <view class="model-content">
            <view class="title">{{ i18n.h2 }}</view>
            <view class="footer-item">
              <view class="cancel" @click="singModel = false">{{
                i18n.h4
              }}</view>
              <view class="confirm" @click="singOut()">{{ i18n.h5 }}</view>
            </view>
          </view>
        </view>
      </view>
    </modal>
  </view>
</template>


<script>
import Clipboard from "clipboard";
import config from "@/config/index.js";
import uniCopy from "@/js_sdk/xb-copy/uni-copy.js";

export default {
  name: "",
  data() {
    return {
      links: "",
      invitelinks: "",
      loginModel: false, //登录
      singModel: false, //退出登录
      addressModel: false, //绑定推荐人
      Recommenderaddres: "", //推荐人地址
      inviteModel: false, //邀请好友
      custmreModel: false, //客服
    };
  },
  computed: {
    i18n() {
      return this.$t("home");
    },
  },
  methods: {
    showAddres() {
      //推荐人地址
      // this.Recommenderaddres = window.location.href.split("id=")[1];
      this.addressModel = true;
    },

    //邀请好友链接
    showInvite() {
      let Linkuser = uni.getStorageSync("user")
        ? uni.getStorageSync("user")
        : "";
      if (Linkuser == "") {
        return;
      }
      this.invitelinks = config.linkUrl + "/#/?id=" + Linkuser;
      // this.invitelinks = "http://localhost:8080/?id=" + Linkuser;
      this.inviteModel = true;
    },
    //平台客服
    showCustomer() {
      this.links = config.customerUrl;
      this.custmreModel = true;
    },
    subInvite(val) {
      //复制
      uniCopy({
        content: val,
        success: (res) => {
          uni.showToast({
            title: this.$t("home.h25"),
            icon: "none",
          });
          this.inviteModel = false;
        },
        error: (e) => {
          uni.showToast({
            title: e,
            icon: "none",
            duration: 3000,
          });
        },
      });
    },

    showLogin() {
      //立即登录
      this.loginModel = true;
    },
    showLoginOut() {
      //退出登录
      this.singModel = true;
    },
    singOut() {
      //退出登录(语言不清除)
      const langval = uni.getStorageSync("akcLang")
        ? uni.getStorageSync("akcLang")
        : "zh";
      const langvs = uni.getStorageSync("lang")
        ? uni.getStorageSync("lang")
        : "zh";
      uni.clearStorage();
      uni.clearStorageSync();
      this.closeModel();
      uni.setStorageSync("lang", langval);
      uni.setStorageSync("lang", langvs);

      location.reload();
    },
    subAddress() {
      this.$emit("value", this.Recommenderaddres);
    },
    closeModel() {
      //弹框关闭
      this.loginModel = false;
      this.singModel = false;
      this.addressModel = false;
      this.inviteModel = false;
      this.custmreModel = false;
    },
  },
};
</script>
<style lang="scss">
.u-input {
  height: 96rpx;
  border-radius: 16rpx;
}
</style>
